﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using WroxGallery.Actions;
using WroxGallery.Models.Interfaces;

namespace WroxGallery.Tests.Actions
{
    /// <summary>
    /// Summary description for TitleActionTest
    /// </summary>
    [TestClass]
    public class TitleActionTest
    {
        private MockRepository mocks;
        private IConfigurationRepository configurationRepository;

        [TestInitialize]
        public void SetupController()
        {
            mocks = new MockRepository();
            configurationRepository = mocks.DynamicMock<IConfigurationRepository>();
        }

        [TestMethod]
        public void TitleActionFilter_Enriches_ViewData_With_GalleryName()
        {
            using (mocks.Record())
            {
                Expect.Call(configurationRepository.GalleryName).Return("Gallery Name");
            }

            TitleFilterAttribute action = new TitleFilterAttribute("Home",configurationRepository);
            ViewDataDictionary viewData = new ViewDataDictionary();
            ActionExecutedContext context = ActionFiltersTestingHelper.GetActionExecutedContext(viewData);

            using (mocks.Playback())
            {
                action.OnActionExecuted(context);

                Assert.AreEqual("Gallery Name", viewData["GalleryName"]);
                Assert.AreEqual("Gallery Name - Home", viewData["Title"]);
            }
        }

        [TestMethod]
        public void TitleActionFilter_Keeps_Original_Title()
        {
            using (mocks.Record())
            {
                Expect.Call(configurationRepository.GalleryName).Return("Gallery Name");
            }

            TitleFilterAttribute action = new TitleFilterAttribute("Home", configurationRepository);
            ViewDataDictionary viewData = new ViewDataDictionary();
            viewData["Title"] = "Album";
            ActionExecutedContext context = ActionFiltersTestingHelper.GetActionExecutedContext(viewData);

            using (mocks.Playback())
            {
                action.OnActionExecuted(context);

                Assert.AreEqual("Gallery Name", viewData["GalleryName"]);
                Assert.AreEqual("Album - Gallery Name - Home", viewData["Title"]);
            }
        }
    }

}
